[rshapes] Fix auto segment rounded-corner math and rounding#5883
Merged
Conversation
Owner
|
@ghera Nice improvement! Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As follow-up to #5875, this PR fixes the auto- segmentation math used by the rounded rectangle path and applies the same rounding correction to the related rshapes helpers.
DrawRectangleRounded()andDrawRectangleRoundedLinesEx()use segments as the subdivision count for a single 90° corner:float stepLength = 90.0f/(float)segments;. Because of that, the correct automatic segment count is based on a quarter circle:ceil((PI/2)/th)or equivalentlyceil((2*PI/th)/4).Using
/2instead computes the subdivision count for a half-circle, which does not match how rounded rectangle corners are actually rendered.This is also consistent with the other auto-segmentation formulas in rshapes, which scale the full-circle segment count by the portion of arc being rendered, e.g.
ceilf((endAngle - startAngle)*(2*PI/th)/360.0f). Rounded rectangle corners are the 90° case of the same logic, which simplifies to/4.This PR also moves
ceilf()to the outside in the affected formulas, so rounding is applied to the final computed segment count rather than to an intermediate full-circle value. That makes the result mathematically consistent for sectors, rings, and rounded rectangle corners.